package yanglei.day0109.travel.service;


import yanglei.day0109.travel.constants.TrTypeStatus;
import yanglei.day0109.travel.dao.TourRouteDao;
import yanglei.day0109.travel.po.TourRoute;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.logging.Logger;

/**
 * @Author: YangLei
 * @CreateTime: 2023-01-08  16:07
 * @Description: TODO
 */
public class TourRouteMgr {
    private Logger logger = Logger.getLogger(String.valueOf(ScenicSpotMgr.class));

    public void showTouRoute(TourRouteDao tourRouteDao) {
        Map<String, Object> map = new HashMap<>();
        System.out.println("显示旅游路线详情:");
        List<TourRoute> tourRoutes = tourRouteDao.queryTourRouteByType(map);
        for (TourRoute t : tourRoutes) {
            System.out.println(t.getTrName() + "\t\t" + TrTypeStatus.getUserStatusByCode(t.getTrType()).getValue() +
                    "\t\t" + t.getTrPrice() + "\t\t" +
                    t.getTrPhone() + "\t\t" + t.getTrUser() + "\t\t" + t.getCreateTime());
        }
    }

    public void addTouRoute(TourRouteDao tourRouteDao, Scanner sc){
        LocalDate date = LocalDate.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        TourRoute tourRoute = new TourRoute();
        System.out.println("请输入旅游路线名称:");
        tourRoute.setTrName(sc.nextLine());
        System.out.println("请输入旅游类型:");
        String trType = sc.nextLine();
        tourRoute.setTrType(Integer.parseInt(trType));
        System.out.println("请输入价格:");
        String trPice = sc.nextLine();
        tourRoute.setTrPrice(Integer.parseInt(trPice));
        System.out.println("请输入咨询电话:");
        tourRoute.setTrPhone(sc.nextLine());
        System.out.println("请输入咨询人姓名:");
        tourRoute.setTrUser(sc.nextLine());
        tourRoute.setCreateTime(date.format(formatter));
        int addRes = tourRouteDao.addTourRoute(tourRoute);
        System.out.println(addRes > 0 ? "录入成功" : "录入失败");

    }

    public void deleteTourRoute(TourRouteDao tourRouteDao,Scanner sc){
        System.out.print("请输入要删除的旅游路线名称：");
        String trName = sc.nextLine();
        int addRes = tourRouteDao.deleteTourRoute(trName);
        System.out.println(addRes > 0 ? "删除成功" : "删除失败");
    }

}
